<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <div>
        已出版书籍：<span>{{ person.books.length > 0 ? 'Yes' : 'No' }}</span>
      </div>
      <div>已出版书籍：<span>{{ booksMessage }}</span></div>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

    <script>
      const { createApp, reactive, computed } = Vue;

      const app = createApp({
        setup() {
          const person = reactive({
            name: "编程段子",
            books: ["HTML", "CSS", "JavaScript"],
          });

          // 返回值为一个计算属性 ref，也需要使用 .value 进行访问
          // 但是 计算属性 ref 也会在模板中自动解包
          const booksMessage = computed(() => {
            // 如果 依赖的相关数据改变，比如这里 person.books 改变，booksMessage 才会更新
            return person.books.length > 0 ? "Yes" : "No";
          });

          return {
            person,
            booksMessage,
          };
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
